<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">
    <link href="${_css}/datatables/tools/css/dataTables.tableTools.css" rel="stylesheet">
	<link rel="stylesheet" href="${_css}/base.css">
    <script src="${_js}/jquery.min.js"></script>
	<script src="${_js}/resize.js"></script>
	<script type="text/javascript" src="${_front_js}/jquery.page.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
	<style>
		td a{
			cursor:pointer
		}
	</style>
</head>


<body style="background: #F7F7F7;">
<div class="">
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
	            <div class="x_title">
					<h2>借款标列表</h2>
					<div class="clearfix"></div>
				</div>
                <div class="pull-right">
                	<button id="query" type="button" class="btn btn-info">查询</button>
                	<button id="export" type="button" class="btn btn-primary export">导出</button>
                </div>
                <form class="form-horizontal form-label-left input_mask" id="borrowRepayForm">
                    <div class="col-md-2 col-sm-2 col-xs-5 form-group has-feedback">
                        <select class="form-control" id="status" >
                        	<option value="" <#if !status?exists>selected="selected"</#if>>--请选择借款标状态--</option>
							<option value="borrow" <#if status?exists & status=='borrow'>selected="selected"</#if>>投资中</option>
							<option value="check" <#if status?exists & status=='check'>selected="selected"</#if>>复审中</option>
							<option value="expire" <#if status?exists & status=='expire'>selected="selected"</#if>>已过期/流标</option>
							<option value="pay" <#if status?exists & status=='pay'>selected="selected"</#if>>还款中/回购中</option>
							<option value="complete" <#if status?exists & status=='complete'>selected="selected"</#if>>已还完</option>
						</select>
                    </div>
                    <form class="form-horizontal">
						<div class="col-md-2 col-sm-2 col-xs-5 form-group has-feedback"><fieldset>
							<div class="control-group">
								<div class="controls">
									<div class="input-prepend input-group">
										<span class="add-on input-group-addon">
											<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
										</span>
										<input type="text" style="width: 200px" name="reservation" id="reservation" placeholder="请选择借款标创建时间段"
										class="form-control" value="<#if createTimeBegin?? & createTimeEnd??>${createTimeBegin}~${createTimeEnd}</#if>" />
									</div>
								</div>
							</div>
						</fieldset>
						</div>
						<div class="col-md-2 col-sm-2 col-xs-5 form-group has-feedback">
						<input type="text" class="form-control has-feedback-left" id="borrow_title" value<#if borrow_title?exists>=${borrow_title}</#if> placeholder="请输入标题">
						</div>
					</form>
                 </form>
                <div class="clearfix"></div>
            </div>
            <div class="scroll">
                <div class="x_content">
                    <table id="example" data-action="/admin/borrow/list?1=1" class="table table-striped responsive-utilities jambo_table">
                        <thead>
                            <tr class="headings">
                                <th>序号 </th>
                                <th>标题</th>
                                <th>借款人姓名</th>
                                <th>标的类型</th>
                                <th>状态</th>
                                <th>借款总额(￥)</th>
                                <th>已投金额 (￥)</th>
                                <th>未投金额(￥)</th>
                                <th>借款期数</th>
                                <th>年化率</th>
                                <th>投资进度</th>
                                <th>还款方式</th>
                                <th>发标时间 </th>
                             	<th>操作</th>
                            </tr>
                        </thead>

                        <tbody>
			                <#if (pageInfo.pageList?size > 0)>
								<#list pageInfo.pageList as model>
									<tr class="even pointer">
		                                <td>
		                                	${model_index+1}
		                                </td>
		                                <td style="width:300px;">
		                                	${model.title!}
		                                </td>
		                                <td >
		                                	${model.realname!}
		                                </td>
		                                <td>
		                                	<#if model.productId?exists>
		                                		<#if productList?exists>
		                                			<#list productList as product>
		                                				<#if model.productId == product.id>${product.name}</#if>
		                                			</#list>
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.status?exists>
		                                		<#if model.status=='borrow'>
		                                			投资中
		                                		<#elseif model.status=='check'>
		                                			复审中
		                                		<#elseif model.status=='expire'>
		                                			已过期/流标
	                                			<#elseif model.status=='pay'>
	                                				还款中
	                                			<#elseif model.status=='complete'>
	                                				已还完
                                				<#elseif model.status=='preview'>
                                				预约中	
		                                		</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.amount?exists>
		                                		<#if (model.amount != 0 )>
			                                		${model.amount?string('#.00')}
			                                	<#else>
			                                	 	${model.amount?string('0.00')}
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.tenderMoney?exists>
		                                		<#if (model.tenderMoney != 0 )>
			                                		${model.tenderMoney?string('#.00')}
			                                	<#else>
			                                	 	${model.tenderMoney?string('0.00')}
			                                	</#if>
		                                	</#if>
		                                </td>		                                
		                                <td>	
		                                	<#if model.notTenderMoney?exists>
		                                		<#if (model.notTenderMoney != 0 )>
			                                		${model.notTenderMoney?string('#.00')}
			                                	<#else>
			                                	 	${model.notTenderMoney?string('0.00')}
			                                	</#if>
		                                	</#if>
		                                </td>		                                		                                
		                                <td>
		                                	<#if model.deadline?exists>
			                                	${model.deadline}
				                        			<#if model.dateUtil?exists && model.dateUtil=='DAY'>
				                        				天
				                        			<#elseif model.dateUtil?exists && model.dateUtil=='MONTH'>
				                        				月	
				                        			</#if>			                                	
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.rewardPercent?exists>
			                                	${model.percent}+${model.rewardPercent?string('0.00')}%
			                                <#else>
			                                	${model.percent}%
		                                	</#if>
		                                	
		                                </td>
										<td class="project_progress">
                                            <div class="progress progress_sm">
                                                <div class="progress-bar bg-green" role="progressbar" data-transitiongoal="${model.schedules}" aria-valuenow="${model.schedules-1}" style="width: ${model.schedules}%;"></div>
                                            </div>
                                            <small>
                                            	已完成
                                            	<#if model.schedules?exists>
					                            	${model.schedules?string('0.00')}%
					                            </#if>
                                            </small>
                                        </td>
		                                <td>
		                                	<#if model.paymentMode?exists>
		                                		<#if model.paymentMode==1>
		                                			一次性还款
		                                		<#elseif model.paymentMode==2>
		                                			等额本息
		                                		<#elseif model.paymentMode==3>
		                                			按月付息到期还本
		                                		</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	${(model.createTime?string("yyyy-MM-dd"))!}	                                	
		                                </td>		                                
		                                 <td>
		                                 	<!--
		                                 	<a class="btn-copy" data-id="${model.id}" href="/admin/borrow/copy?bid=${model.id}">复制标&nbsp;&nbsp; </a> 
		                                 	<#if model.status=="borrow">
		                                 		<a class="btn-cancel" data-id="${model.id}">流标&nbsp;&nbsp; </a> 
		                                 	</#if>-->
		                                	<#if model.status=="check">
		                                		 <a class="btn-complete" data-id="${model.id}" id="check">满标复审</a>&nbsp;&nbsp; 
		                                		  <a class="btn-complete" data-id="${model.id}" id="quit">流标</a>&nbsp;&nbsp;
		                                	<#elseif model.status="pay" || model.status="complete">
		                                		 <a class="btn-pay" data-id="${model.id}" href="/admin/borrowPayment/listBorrowPayment?borrowId=${model.id}">查看还款</a>&nbsp;&nbsp; 
		                                		 <a class="btn-detail" data-id="${model.id}" href="/admin/borrow/detailBorrow?borrowId=${model.id}">查看/编辑</a>&nbsp;&nbsp;
		                        			</#if>       
		                        			<#if (model.status=="borrow") || (model.status=="unpublish")>
		                        				<a class="btn-detail" data-id="${model.id}" href="/admin/borrow/detailBorrow?borrowId=${model.id}">查看/编辑</a>&nbsp;&nbsp;   
		                        			</#if>
		                        			<!--<a class="btn-detail" data-id="${model.id}" href="/admin/borrow/detailBorrow?borrowId=${model.id}">详情</a>-->
		                                </td>
		                             </tr>   
		                        </#list>
							<#else>
								<tr class="even pointer">
									<td colspan="15">无记录</td>
								</tr>
							</#if>
                        </tbody>
                    </table>
                    <#if (pageInfo.pageList?size > 0)>
	                	<#include "../base/Page.ftl">
	                </#if>
	                <div id="pageCollect">
	                	<#if (pageInfo.pageList?size > 0)>
							共计：<span style="color:#1ABB9C"><#if pageInfo.total?exists>${pageInfo.total}</span></#if>笔，
							贷款总额：<span style="color:#1ABB9C"><#if pageInfo.sum?exists>${pageInfo.sum?string('0.00')}</span></#if>元，
							剩余本金：<span style="color:#1ABB9C"><#if pageInfo.sumBlance?exists>${pageInfo.sumBlance?string('0.00')}</span></#if>元，
							已还总额：<span style="color:#1ABB9C"><#if pageInfo.sumFee?exists>${pageInfo.sumFee?string('0.00')}</span></#if>元
		                </#if>
	                </div>
                </div>
            </div>
        </div>
        <br />
    </div>
</div>

<script src="${_js}/bootstrap.min.js"></script>

<!-- bootstrap progress js -->
<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
<!-- icheck -->
<script src="${_js}/icheck/icheck.min.js" type="text/javascript"></script>

<script src="${_js}/custom.js" type="text/javascript"></script>

<!-- PNotify -->
<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>

<!-- daterangepicker -->
<script type="text/javascript" src="${_js}/datepicker/moment.min2.js"></script>
<script type="text/javascript" src="${_js}/datepicker/daterangepicker.js"></script>
<script type="text/javascript" src="${_front_js}/date.js"></script>

<script type="text/javascript" src="${_front_js}/layer/layer.js" ></script>
<script type="text/javascript" src="${_front_js}/layer/extend/layer.ext.js" ></script>

<script>
    $(document).ready(function () {
        $('input.tableflat').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass: 'iradio_flat-green'
        });
        
        $('#reservation').daterangepicker(null, function (start, end, label) {
            //console.log(start.toISOString(), end.toISOString(), label);
        });
        
        $(".btn-cancel").click(function(){
        	var id=$(this).attr("data-id");
        	if(confirm('你确定要进行流标吗 ？')){
	        	$.ajax({
		            type: 'post',
		            dataType: 'JSON',
		            async:'false',
		            url: '/admin/borrow/cancel',
		            data:{borrowId:id},
		            success: function(result){
		            	if(result.code==-1){
				        	window.location.href="/hf/borrow/cancel?bid="+id;
		            	}else{
		            	    alert(result.msg);  	 
				        	return false;           	
		            	}
		            }
	            });  
        	}
        })

		function createXMLHTTPRequest() {     
             //1.创建XMLHttpRequest对象     
             //这是XMLHttpReuquest对象无部使用中最复杂的一步     
             //需要针对IE和其他类型的浏览器建立这个对象的不同方式写不同的代码     
             var xmlHttpRequest;  
             if (window.XMLHttpRequest) {     
                 //针对FireFox，Mozillar，Opera，Safari，IE7，IE8     
                xmlHttpRequest = new XMLHttpRequest();     
                 //针对某些特定版本的mozillar浏览器的BUG进行修正     
                 if (xmlHttpRequest.overrideMimeType) {     
                     xmlHttpRequest.overrideMimeType("text/xml");     
                 }     
             } else if (window.ActiveXObject) {     
                 //针对IE6，IE5.5，IE5     
                 //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中     
                 //排在前面的版本较新     
                 var activexName = [ "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ];     
                 for ( var i = 0; i < activexName.length; i++) {     
                     try {     
                         //取出一个控件名进行创建，如果创建成功就终止循环     
                         //如果创建失败，回抛出异常，然后可以继续循环，继续尝试创建     
                        xmlHttpRequest = new ActiveXObject(activexName[i]);   
                        if(xmlHttpRequest){  
                            break;  
                        }  
                     } catch (e) {     
                     }     
                 }     
             }     
             return xmlHttpRequest;  
         }  
                     
        $("#check").click(function(){
        	var id=$(this).attr("data-id");
        	if(confirm('你确定要进行满标复审吗 ？')){
        		var index = layer.load(1,{shade: [0.8, '#393D49']});
             
			       $.ajax({
			            type: "post", 
			            dataType: "json", 
			            url: "/fuion/borrow/complete",
			            data: {
			                "borrowId":id
			            }, 
			            success: function (result) { 
			            	if(result.code==-1){
		                    	layer.alert("操作成功!",function(index){
		                    		layer.close(index);
		                    		window.location.reload();
		                    	});            		
			            	}else{
			            		layer.alert("操作失败!")
			            		layer.close(index);
	                    		//window.location.reload();
			            	}
			            }
			       });   		               
		    }	                  		
        })
        
          $("#quit").click(function(){
        	var id=$(this).attr("data-id");
        	if(confirm('你确定要进行撤销标吗？')){
        		var index = layer.load(1,{shade: [0.8, '#393D49']});
			       $.ajax({
			            type: "post", 
			            dataType: "json", 
			            url: "/borrow/cancel/mark",
			            data: {
			                "borrowId":id
			            }, 
			            success: function (result) { 
			            	if(result.code==-1){
		                    	layer.alert("操作成功!",function(index){
		                    		layer.close(index);
		                    		window.location.reload();
		                    	});            		
			            	}else{
			            		layer.alert("操作失败!")
			            		layer.close(index);
	                    		//window.location.reload();
			            	}
			            }
			       });   		               
		    }	                  		
        })
        
    });
    
    function initData(action) { 
    	var status = $("#status").find("option:selected").val();
    	var reservation = $("#reservation").val();
    	var b_title=($("#borrow_title").val()).trim();
    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
    	if(reservation !="" && !reg.test(reservation)){
			new PNotify({
		            	title: '操作提示',
		            	text: '时间格式错误！',
		            	delay: 3e3,
		            	type: 'error'
		        	});
		    return false;
		}
    	if(status != ""){
    		action += "&status="+status;
    	}
    	if(reservation !=""){
    		var splitChar = "~";
    		if(reservation.indexOf(splitChar) != -1){
    			var createTimeBegin = $.trim(reservation.split(splitChar)[0]);
    			var createTimeEnd = $.trim(reservation.split(splitChar)[1]);
    			action +="&createTimeBegin="+createTimeBegin;
    			action +="&createTimeEnd="+createTimeEnd;
    		}
    	}
    	if(b_title!=""){
    	 action +="&borrow_title="+b_title;
    	}
		window.location.href=encodeURI(encodeURI(action));
	} 
	
	$(".btn-info").click(function(){
		initData($("#example").attr('data-action'));
	});
	
	var createTimeBegin = "<#if createTimeBegin?exists>${createTimeBegin}</#if>";
	var createTimeEnd = "<#if createTimeEnd?exists>${createTimeEnd}</#if>";
	if(createTimeBegin != "" && createTimeEnd != ""){
		document.getElementById("reservation").value=createTimeBegin+"~"+createTimeEnd;
	}
	
	//发标
	$(".rate").click(function(){
		var bid = $(this).attr("data-id");
		$.ajax({
            type: 'get',
            dataType: 'JSON',
            async:'false',
            url: '/hf/borrow/register',
            data:{bid:bid},
            success: function(result){
            	layer.alert(result.msg);
            }
        }); 
	})	
	
	//导出
	$("#export").click(function(){
			var count=0;
			var action="/admin/export/borrow/list?1=1";
	    	var status = $("#status").find("option:selected").val();
	    	var reservation = $("#reservation").val();
	    	var b_title=($("#borrow_title").val()).trim();
	    	$("tbody .tableflat").each(function(){
						if($(this).parent().hasClass('checked')){
							ids[count]=$(this).attr("data-id");
							count++;
						}
					})
	    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
	    	if(reservation !="" && !reg.test(reservation)){
				new PNotify({
			            	title: '操作提示',
			            	text: '时间格式错误！',
			            	delay: 3e3,
			            	type: 'error'
			        	});
			    return false;
			}
	    	if(status != ""){
	    		action += "&status="+status;
	    	}
	    	if(reservation !=""){
	    		var splitChar = "~";
	    		if(reservation.indexOf(splitChar) != -1){
	    			var createTimeBegin = $.trim(reservation.split(splitChar)[0]);
	    			var createTimeEnd = $.trim(reservation.split(splitChar)[1]);
	    			action +="&createTimeBegin="+createTimeBegin;
	    			action +="&createTimeEnd="+createTimeEnd;
	    		}
	    	}
	    	if(b_title!=""){
	    	 action +="&borrow_title="+b_title;
	    	}
			window.location.href=encodeURI(encodeURI(action));
		});	
</script>
</body>
</html>